package com.website.web.front.controller;

import com.website.common.core.controller.BaseController;
import com.website.custom.domain.WAbout;
import com.website.custom.domain.WBrand;
import com.website.custom.domain.WDevelop;
import com.website.custom.domain.WHonorCharm;
import com.website.custom.service.IWAboutService;
import com.website.custom.service.IWBrandService;
import com.website.custom.service.IWDevelopService;
import com.website.custom.service.IWHonorCharmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

@Controller
public class AboutController extends BaseController {

    @Autowired
    private IWAboutService aboutService;

    @Autowired
    private IWBrandService wBrandService;

    @Autowired
    private IWDevelopService wDevelopService;

    @Autowired
    private IWHonorCharmService wHonorCharmService;

    /**
     * 关于我们
     * @param request
     * @param response
     * @param model
     * @return
     */
    @GetMapping("/about")
    public String about(HttpServletRequest request, HttpServletResponse response, ModelMap model) {
        // 公司介绍
        WAbout wAbout = aboutService.selectWAboutById(1l);
        model.addAttribute("wAbout", wAbout);
        // 品牌文化
        List<WBrand> wBrands = wBrandService.selectWBrandList(null);
        model.addAttribute("wBrands", wBrands);
        // 发展历程
        List<WDevelop> WDevelops = wDevelopService.selectWDevelopList(null);
        model.addAttribute("wDevelops", WDevelops);
        // 企业荣誉与风采
        List<WHonorCharm> WHonorCharms = wHonorCharmService.selectWHonorCharmList(null);
        List<WHonorCharm> honorList = new ArrayList<>();
        List<WHonorCharm> charmList = new ArrayList<>();

        WHonorCharms.forEach(item-> {
            if(item.getwType()==0){
                honorList.add(item);
            }else {
                charmList.add(item);
            }
        });
        model.addAttribute("honorList", honorList);
        model.addAttribute("charmList", charmList);
        return "front/about";
    }

    @GetMapping("/honorcharm/detail")
    public String detail(HttpServletRequest request, HttpServletResponse response, @RequestParam("hcId") String hcId, ModelMap model) {
        WHonorCharm wHonorCharm = wHonorCharmService.getById(Long.parseLong(hcId));
        model.addAttribute("wHonorCharm", wHonorCharm);
        return "front/honor_charm_details";
    }
}
